﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using VswService_V7.Utility;

namespace VswService_V7.DataBase.Tables
{
    /// <summary>
    /// wp code
    /// </summary>
    public partial class RECIPE_EVENT
    {
        public static int pageNum = 20;
        /// <summary>
        /// pagination query recipelog infromation
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="minRow"></param>
        /// <param name="maxRow"></param>
        /// <param name="TotalPages"></param>
        /// <returns></returns>
        public static DataTable QueryRecipeLog(string sql, int minRow, int maxRow, out string TotalPages)
        {
            try
            {
                string sqlrecipelog = string.Format("select * from ({0} order by {1} asc,{2} asc) where rn>{3} and rn<={4}",
                  sql, fd_updateDate, fd_recipeNo, minRow, maxRow);
                string sqlrecipelogCount = string.Format("select count(*) from ({0})",
                   sql);
                DataTable recipelogTable = OracleHelper.Exct_QueryTable(sqlrecipelog);
                if (recipelogTable != null)
                {
                    int recipelogPages = Convert.ToInt32(TASK_INFO.GetTableCount(sqlrecipelogCount));
                    if (recipelogPages % pageNum == 0)
                    {
                        TotalPages = (recipelogPages / pageNum).ToString();
                    }
                    else
                    {
                        TotalPages = (recipelogPages / pageNum + 1).ToString();
                    }
                    LogHelper.WriteLog("QueryRecipeLog Success");
                    return recipelogTable;
                }
                else
                {
                    TotalPages = "";
                    return null; ;
                }

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("QueryRecipeLog", ex);
                throw ex;
            }
        }
    }
}
